package com.example.activities;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import com.example.activities.Module.Student;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button ZhangSan = findViewById(R.id.ZhangSan);
        ZhangSan.setOnClickListener( view -> {
        Intent intent = new Intent(MainActivity.this, AnotherActivity.class);

            //intent.putExtra(String name, char value)
            intent.putExtra("name", "ZhangSan");
            //intent.putExtra(String name, int value)
            intent.putExtra("age", 20);

            Student student = new Student();
            student.setName("ZhangSan");
            student.setAge(20);
            intent.putExtra("student", student);

            startActivityForResult(intent, 1);
        });

        Button LiSi = findViewById(R.id.LiSi);
        LiSi.setOnClickListener( view -> {

            Intent intent = new Intent(MainActivity.this, AnotherActivity.class);

            //intent.putExtra(String name, char value)
            intent.putExtra("name", "LiSi");
            //intent.putExtra(String name, int value)
            intent.putExtra("age", 19);

            Student student1 = new Student();
            student1.setName("LiSi");
            student1.setAge(19);
            intent.putExtra("student", student1);

            startActivityForResult(intent,2);
        });

        Intent intent = getIntent();
        String str = intent.getStringExtra("result");
        TextView textView = findViewById(R.id.textViewMain);
        textView.setText(str);
    }

}